package com.jews.jpa.converter;

import com.jews.common.constants.ValidStatus;

import javax.persistence.AttributeConverter;

/**
 * 状态枚举转换器
 *
 * @author JewsChen
 * @title: ValidStatusConverter
 * @date 2022/11/27 23:57
 */
public class ValidStatusConverter implements AttributeConverter<ValidStatus, Integer> {

    @Override
    public Integer convertToDatabaseColumn(ValidStatus validStatus) {
        return validStatus.getCode();
    }

    @Override
    public ValidStatus convertToEntityAttribute(Integer code) {
        return ValidStatus.of(code).orElse(null);
    }
}
